import { Navigate } from "react-router-dom";
import type { RouteObjects } from './interface'
import Login from '../pages/login/index'

// 导入所有router
const allRouters = import.meta.glob('./modules/*.tsx', { eager: true })

// 处理路由
export const routerArray: RouteObjects[] = []

Object.keys(allRouters).forEach((item) => {
  routerArray.push(...(allRouters[item] as any).default)
})

export const rootRouter: RouteObjects[] = [
  {
    path: '/',
    element: <Navigate to="/login" />,
  },
  {
    path: '/login',
    element: <Login />,
    meta: {
      requiresAuth: false,
      title: '登录页',
      key: 'login',
    }
  },
  ...routerArray,
  {
    path: '*',
    element: <Navigate to="/404" />,
  }
]